//
//  WelcomeViewController.m
//  mUBB
//
//  Created by Cosmin Stirbu on 2/24/13.
//  Copyright (c) 2013 Cosmin Stirbu. All rights reserved.
//

#import "WelcomeViewController.h"
#import "SignInViewController.h"
#import "HomeViewController.h"

@interface WelcomeViewController ()

@end

@implementation WelcomeViewController

@synthesize teacherButton, studentButton, checkBoxButton, signInLabel, welcomeLabel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    // Set up the UI
    [Utils customizeButton:teacherButton withBgImageKey:@"button_image" imageKey:nil textKey:@"TEACHER_BUTTON" textColorKey:@"welcome_screen_buttons_text_color"];
    
    [Utils customizeButton:studentButton withBgImageKey:@"button_image" imageKey:nil textKey:@"STUDENT_BUTTON" textColorKey:@"welcome_screen_buttons_text_color"];
    
    [Utils customizeButton:checkBoxButton withBgImageKey:nil imageKey:@"checkbox_unchecked" textKey:@"REMEMBER_OPTION" textColorKey:@"welcome_screen_labels_color"];
    
    UIImage *checkedImage = [UIImage imageNamed:[[ConfigurationManager instance] UIConfigValueForKey:@"checkbox_checked"]];
    
    [checkBoxButton setImage:checkedImage forState:UIControlStateSelected];
    
    [Utils customizeLabel:welcomeLabel withTextKey:@"WELCOME_LABEL" textColorKey:@"welcome_screen_labels_color"];

    [Utils customizeLabel:signInLabel withTextKey:@"SIGN_IN_LABEL" textColorKey:@"welcome_screen_labels_color"];
 
    
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    if (!_studentButtonPressed) {
        [self.navigationController setNavigationBarHidden:NO animated:animated];
    }
    [super viewWillDisappear:animated];
}

#pragma mark - UI Interaction

- (IBAction)teacherButtonPressed:(id)sender {
    SignInViewController *signInViewController = [[SignInViewController alloc] initWithNibName:@"SignInViewController" bundle:nil];
    [self.navigationController pushViewController:signInViewController animated:YES];
}

- (IBAction)studentButtonPressed:(id)sender {
    _studentButtonPressed = YES;
    
    [[ConfigurationManager instance] setApplicationConfigValue:[NSNumber numberWithBool:checkBoxButton.selected] forKey:REMEMBER_OPTION];
    [[ConfigurationManager instance] saveApplicationConfig];
    
    HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
    navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:navigationController animated:YES];
}

- (IBAction)rememberButtonPressed:(id)sender {
    [checkBoxButton setSelected:!checkBoxButton.selected];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setTeacherButton:nil];
    [self setStudentButton:nil];
    [self setCheckBoxButton:nil];
    [self setSignInLabel:nil];
    [self setWelcomeLabel:nil];
    [super viewDidUnload];
}
@end
